<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
	<TITLE></TITLE>
	<META NAME="GENERATOR" CONTENT="OpenOffice.org 2.4  (Linux)">
	<META NAME="AUTHOR" CONTENT="Onko">
	<META NAME="CREATED" CONTENT="20090515;4011900">
	<META NAME="CHANGEDBY" CONTENT="Onko">
	<META NAME="CHANGED" CONTENT="20090515;5285500">
	<STYLE TYPE="text/css">
	<!--
		@page { size: 21.59cm 27.94cm; margin: 2cm }
		P { margin-bottom: 0.21cm }
	-->
	</STYLE>
</HEAD>
<BODY LANG="en-CA" DIR="LTR">
<P STYLE="margin-bottom: 0cm"><FONT FACE="Arial, sans-serif"><U><B>Assignment
#1</B></U></FONT></P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Arial, sans-serif"><B>Ondrej
Ruttkay</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Arial, sans-serif"><B>20179429</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Arial, sans-serif"><B>CS
452</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Arial, sans-serif"><I><B>Program
user guide</B></I></FONT></P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">The
program provides a standard terminal console to input commands that
communicate with the train controller. The following commands are
supported:</SPAN></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">	</SPAN><B>tr
&lt;train_number&gt; &lt;train_speed&gt; </B><SPAN STYLE="font-weight: medium">–
Sets any train in motion at the desired speed </SPAN></FONT>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">	(0
for stop)</SPAN></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">	</SPAN><B>rv
&lt;train_number&gt; </B><SPAN STYLE="font-weight: medium">– The
train reverses direction by having its speed set to zero, 	changes
direction, then accelerates to its previous speed</SPAN></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">	</SPAN><B>sw
&lt;switch_number&gt; &lt;switch_direction ('S' or 'C')&gt;</B><SPAN STYLE="font-weight: medium">
– Throws the given switch</SPAN></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal">   <FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">	to
straight (S) or curved (C)</SPAN></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">	</SPAN><B>wh
</B><SPAN STYLE="font-weight: medium">– Displays on the monitor the
number of the last sensor that was triggered</SPAN></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">	</SPAN><B>st
&lt;switch_number&gt; </B><SPAN STYLE="font-weight: medium">–
Displays on the monitor the state into which the switch was 	most
recently switched</SPAN></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">	</SPAN><B>q
</B><SPAN STYLE="font-weight: medium">– Exits the program</SPAN></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><FONT FACE="Arial, sans-serif"><SPAN STYLE="font-weight: medium">Path
to the executable: </SPAN><FONT FACE="Courier 10 Pitch"><SPAN STYLE="font-weight: medium">/u2/oruttkay/cs452/a1/a1.elf</SPAN></FONT></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Arial, sans-serif"><I><B>Program
design description</B></I></FONT></P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">The basis construct of the program is
the polling loop located in the main() function. The purpose is to
continuously check and update different aspects of the program, while
keeping within the constraints of the real-time environment. The
polling loop is supposed to service 3 important functions: update the
timer without losing any ticks; accept input from the terminal and
check the sensor triggers on the track.</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">Before the polling loop starts, all of
the global variables get initialized, the track switches are reset to
curved position, the train is set to speed 0 and a command is sent to
clear the sensor banks.</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">In my program I have implemented the
timer and the input to be inside the polling loop, however, the state
of the track sensors is not polled due to a bug in my code, which was
freezing input of other commands. So to make the program usable, I've
removed the polling of sensors and I just programmed it to work per
request. The “wh” command is implemented and it returns the name
of the last sensor triggered, but it checks sensors only during the
command call.</FONT></P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT FACE="Arial, sans-serif"><I>Timer</I></FONT></P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">To keep track of the elapsed time
since the start of the program I'm using the 32-bit timer on the
board. Initially, I set the timer value to 0x0fffffff, I choose the
2kHz frequency and then I let it count downwards. In order to update
the value every tenth of the second I make sure I poll the timer
value once every 200 timer cycles. I have put the time checking into
a separate function so that it could be called from other parts of
the code that wouldn't be able to return back to the polling loop
within 1 tenth of a second.</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT FACE="Arial, sans-serif"><I>Command
line interface</I></FONT></P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">The recieve-full register of the UART
2 is continuously polled if any input from the user has arrived. If
it has, it is inserted into the command buffer and after the Enter
key is pressed, the entire string is sent to the parser. The string
is tokenized to a command name, arguments and it is checked for
validity. I have created a struct, which is passed to the parser and
it is filled with a parsed command.</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT FACE="Arial, sans-serif"><I>Command
execution</I></FONT></P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">During every command execution the
program sends the appropriate byte values to the train controller.
However, for some of the commands, multiple bytes need to be sent,
but if they are sent right after one other, the controller doesn't
accept them. That is why I've implemented the stall() function, which
takes the length of a delay (in milliseconds) as a parameter and for
the specified amount of time it updates the timer. After this delay
expires, the execution continues by sending the next command bytes.</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT FACE="Arial, sans-serif"><I>I/O</I></FONT></P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">why i changed bw na putc/getc</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT FACE="Arial, sans-serif"><I>The
UARTs</I></FONT></P>
<P STYLE="margin-bottom: 0cm; font-weight: medium"><BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">Just to note that I have enabled the
FIFO on COM2 in order to speed up the output transmission to the
terminal and I've decided to keep it off for COM1, because the FIFO
might be sending the bytes to the track controller too fast and it
could crash it.</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif"><BR><I><B>Program files and MD5 hashes</B></I></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">The source code is in the following
directory: <FONT FACE="Courier 10 Pitch">/u2/oruttkay/cs452/a1/src/</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">The following are the files being
submitted:</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<BR>
</P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">MD5 (a1.elf) =
4b797d8bc4915391d7aa3ac805196d79</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">MD5 (Makefile) =
2845ec45680c601d6099bba195b6acc9</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">MD5 (a1.c) =
dc8984aa88be3178f0c961150759f71b</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">MD5 (a1.h) =
e8f6e219258c2aea8868d29bc517c451</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">MD5 (a1_help.c) =
ba0c37da18f29ee5b4acfcdf34afb419</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">MD5 (a1_io.c) =
65abd1187476f6615334b21274ccafc9</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">MD5 (a1_que.c) =
0c586acc3ca04169abb3a29aab3d5bb0</FONT></P>
<P STYLE="margin-bottom: 0cm; font-style: normal; font-weight: medium">
<FONT FACE="Arial, sans-serif">MD5 (orex.ld) =
bab18d804f1a49ddcec6a6f81f7e8e25</FONT></P>
</BODY>
</HTML>